<?php
class NoBusinessBase_Helper_Jsonr extends Zend_Controller_Action_Helper_Json
{
   public function direct($data, $pSortAndRange = null, $total = -1, $sendNow = true, $keepLayouts = false, $encodeData = true)
   {
      $this->suppressExit = true;

      if(!is_array($data))
         return parent::direct($data, $sendNow, $keepLayouts, $encodeData);

      $response = $this->getResponse();
      $headers = $response->getHeaders();
      array_shift($headers);
      foreach($headers as $header)
      {
         $name = $header["name"];
         if($name === "Content-Range")
            return parent::direct($data, $sendNow, $keepLayouts, $encodeData);
      }

      if($pSortAndRange && $total >= 0)
         $pSortAndRange->setContentRangeHeader(count($data), $total);
      else
      {
         $total = count($data);
         $start = 0;
         $end = $total - 1;

         $response->setHeader("Content-Range", $start . '-' . $end . '/' . $total);
      }

      return parent::direct($data, $sendNow, $keepLayouts, $encodeData);
   }
}

